const mongoose = require("mongoose")
const ObjectId = mongoose.Schema.Types.ObjectId;
const StoresSchema = new mongoose.Schema({
    // 门店数据模型
    name: String, //店名
    businessphone: String,   //营业执照号码
    businessimg: String, //营业执照照片
    address: String,  //店地址
    positioning: String,  //定位
    city: String, //所在城市
    method: String, //法人
    phone: String, //联系电话
    headimg: String, //门店法人大头照
    commissionratio: String,  //佣金比例
    salesnum: Number, //销售记录 
    target:Number, //完成目标
    employees: [{ //员工
        name: String,  //员工姓名
        rank: String, // 员工职位
        phone: String  //员工电话
    }],
    service: [{ //服务
    name: String,   //服务名称
    timeconsuming: Number,  //耗时多久
    price: Number  //价格
    }],
    good:[{
        nickname: String,    //商品名
        category: String,    //商品类别，狗粮、猫粮 
        taste: String,   //商品口味
        price: Number  //价格
    }],
    state: Boolean,  //状态
    Supplier:{  //关联的供应商
        type: ObjectId,
        ref: "Supplier"
    },
    isHot: Boolean  //是否时热门
}, {
        versionKey: false,
        timestamps: {
            createdAt: 'createTime',
            updatedAt: 'updateTime'
        } //自动管理修改时间
    })
const stores = mongoose.model("stores", StoresSchema);
async function add() {
    const res = await stores.countDocuments()
    if (res === 0) {
        stores.create({
            name: "bbj",
            businessphone: "110",
            businessimg: "",
            address: "成都",
            positioning: "",
            city: "成都",
            method: "xzx",
            phone: "10086",
            headimg: "",
            commissionratio: "1:2",
            salesnum:10, //完成进度
            target:100, //完成目标
            employees: [],
            good:[],
            service:[],
            state:false
        })
        stores.create({
            name: "afanfan",
            businessphone: "110",
            businessimg: "",
            address: "成都",
            positioning: "",
            city: "成都",
            method: "xzx",
            phone: "10086",
            headimg: "",
            commissionratio: "1:2",
            salesnum:45, //完成进度
            target:100, //完成目标
            employees: [],
            good:[],
            service:[],
            state:false

        })
        stores.create({
            name: "axixixi",
            businessphone: "110",
            businessimg: "",
            address: "成都",
            positioning: "",
            city: "成都",
            method: "xzx",
            phone: "10086",
            headimg: "",
            commissionratio: "1:2",
            salesnum:25, //完成进度
            target:100, //完成目标
            employees: [],
            good:[],
            service:[],
            state:true

        })
        


    }
}
add()
module.exports = stores;